using Godot;

namespace MyCraft2;

public partial class MainContainer : CenterContainer
{
	[Export] public TextureRect? Crosshair;
	[Export] public Button? CloseButton;
	[Export] public LineEdit? SetDayTimeEdit;

	public override void _Input(InputEvent @event)
	{
		base._Input(@event);

		if (@event is InputEventKey { Pressed: false } eventKey)
		{
			switch (eventKey.Keycode)
			{
				case Key.Escape:
					if (CloseButton is not null && CloseButton.Visible)
					{
						CloseButton.Visible = false;
						Input.MouseMode = Input.MouseModeEnum.Captured;
						if(Crosshair is not null)Crosshair.Visible = true;
					}
					else if (SetDayTimeEdit is not null && SetDayTimeEdit.Visible)
					{
						SetDayTimeEdit.Visible = false;
						SetDayTimeEdit.Text = "";
						Input.MouseMode = Input.MouseModeEnum.Captured;
						if(Crosshair is not null)Crosshair.Visible = true;
					}
					else if (CloseButton is not null)
					{
						CloseButton.Visible = true;
						Input.MouseMode = Input.MouseModeEnum.Visible;
						if(Crosshair is not null)Crosshair.Visible = false;
					}
					break;
				case Key.T:
					if (SetDayTimeEdit is not null && !SetDayTimeEdit.Visible && CloseButton is not null && !CloseButton.Visible)
					{
						SetDayTimeEdit.Visible = true;
						SetDayTimeEdit.GrabFocus();
						Input.MouseMode = Input.MouseModeEnum.Visible;
						if(Crosshair is not null)Crosshair.Visible = false;
					}
					break;
			}
		}
	}
}
